﻿namespace Web.Control.WWW.Lesson
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Model.WWW_User.Teach;
    using BLF.WWW_User.Teach;
    using Lx.Web.Common.ControlsUI;
    using System.Collections;
    using System.Collections.Generic;
    public class sessions : BaseControl
    {   
        /// <summary>
        /// 登陆的会员号
        /// </summary>
        protected string memberno = "";
        /// <summary>
        /// lesson id
        /// </summary>
        protected string lid;
        /// <summary>
        /// couresmodel 其中的Sessions和Views都为lesson、
        /// </summary>
        protected CoursesModel cm=new CoursesModel();
        protected System.Globalization.CultureInfo CurLan = new System.Globalization.CultureInfo(Lx.Web.Common.UI.Globals.Language);
        /// <summary>
        /// 该会员的总sessions数
        /// </summary>
        protected int asession = 0;
        protected LessonModel lm = null;
        protected Repeater repsess;
        /// <summary>
        /// 页面
        /// </summary>
        protected int pageIndex = 1;
        protected Literal lLCount;
        private int l = 15;
        /// <summary>
        /// 数据数量st,gtype,p,ll
        /// </summary>
        protected int RecordCount = 0;
        protected List<SessionsModel> smlist;
        protected string Timezone = "0";
        protected override void OnLoad(EventArgs e)
        {
            memberno = HttpContext.Current.User.Identity.Name;
            ArrayList arrlist = new ArrayList();
            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["p"] == "L")
                {
                    pageIndex = 9999;
                }
                else
                {
                    int.TryParse(Request["p"], out pageIndex);
                }
            }
            if (lLCount != null) int.TryParse(lLCount.Text, out l);
            if (!string.IsNullOrEmpty(Request["lid"]))
            {
                lid = Request["lid"];
            }
            else
            {
                Response.End();
            }
            arrlist=Teach.GetALessonSessions(memberno, lid,pageIndex,l);
            if (arrlist != null && arrlist.Count > 0)
            {
                RecordCount = (int)arrlist[5];
                Timezone = arrlist[3].ToString();
                int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)l));
                if (pageIndex > pCount) pageIndex = pCount;
                cm = arrlist[0] as CoursesModel;
                lm = arrlist[2] as LessonModel;
                asession = (int)arrlist[1];
                smlist = arrlist[4] as List<SessionsModel>;
                if (repsess != null)
                {
                    repsess.DataSource = smlist;
                    repsess.DataBind();
                }
                //title
                this.DynamicTitle = GetText("{0}: Sessions - italki {1} Lessons", new string[] { lm.Title, BLF.StaticData.GetLanguageText(cm.LanguageLearn) });
                this.DynamicKeywords = GetText("{0}, session, lesson, {1}", new string[] { lm.Title, BLF.StaticData.GetLanguageText(cm.LanguageLearn) });
                this.DynamicDescription = GetText("Latest sessions of {0} at italki", new string[] { lm.Title });
            }
            else
            {
                Response.End();
                return;
            }
            base.OnLoad(e);
        }
    }
}